/**
 * 学习打卡相关API类型定义
 */

import type { PageParams, TimestampInfo } from './common'
import type { RecentReadingRespVO } from './record'

// 分页结果
export interface PageResult<T> {
  list: T[]
  total: number
}

// 学习打卡创建请求
export interface PunchCreateReqVO {
  readingTime: number
  bookIds: number[]
  commentText: string // 修改字段名以匹配后端
  isPublic?: boolean // 是否公开显示
  mood?: string
  achievements?: string[]
}

// 学习打卡响应
export interface PunchRespVO extends TimestampInfo {
  id: number
  userId: number
  punchDate: string
  readingTime: number
  bookCount: number
  commentText?: string // 修改字段名以匹配后端
  mood?: string
  achievements?: string[]
  booksRead: RecentReadingRespVO[]
}

// 打卡记录响应 - 匹配后端PunchRecordRespVO
export interface PunchRecordRespVO {
  id: number
  punchDate: string // LocalDate会被序列化为字符串
  commentText: string
  bookCount: number
  dayCount: number
  readingTime: number // 当日阅读时长（秒）
  isPublic: boolean
  books: PunchBookVO[]
  createTime?: string // 创建时间
  updateTime?: string // 更新时间
  userInfo?: UserInfoVO // 用户信息
  isFollowed?: boolean // 是否已关注该用户
}

// 用户信息
export interface UserInfoVO {
  userId: number
  username: string
  nickname?: string
  avatar?: string
}

// 打卡绘本信息 - 匹配后端PunchBookVO
export interface PunchBookVO {
  id: number
  title: string
  cover?: string
  bookSetTitle?: string
}

// 打卡日历响应 - 匹配后端PunchCalendarRespVO
export interface PunchCalendarRespVO {
  yearMonth: string
  punchDays: PunchDayVO[]
  stats: PunchStatsVO
}

// 打卡日期信息
export interface PunchDayVO {
  date: number[] | string // LocalDate会被序列化为数组格式 [年, 月, 日] 或字符串
  isPunched: boolean
  bookCount: number
}

// 打卡统计信息
export interface PunchStatsVO {
  monthPunchDays: number
  totalPunchDays: number
  currentStreak: number
  maxStreak: number
}

// 打卡统计响应 - 匹配后端UserStatsRespVO
export interface PunchStatsRespVO {
  totalPunchDays: number
  consecutiveDays: number // 后端字段名
  maxConsecutiveDays: number // 后端字段名
  thisMonthPunchDays: number
  totalReadingTime: number
  totalBooksRead: number
  averageReadingTime: number
  punchRate: number // 打卡率
  // 月度统计
  monthlyStats: Array<{
    month: string
    punchDays: number
    readingTime: number
    bookCount: number
  }>
  // 周统计
  weeklyStats: Array<{
    week: string
    punchDays: number
    readingTime: number
    bookCount: number
  }>
}

// 今日打卡响应
export interface TodayPunchRespVO {
  hasPunched: boolean
  punchRecord?: PunchRespVO
  canPunchToday: boolean
  todayReadingTime: number
  todayBooksRead: RecentReadingRespVO[]
  suggestions?: string[]
}

// 打卡列表参数
export interface PunchListParams extends PageParams {
  startDate?: string
  endDate?: string
  mood?: string
  minReadingTime?: number
  maxReadingTime?: number
}

// 打卡日历参数
export interface PunchCalendarParams {
  year: number
  month: number
}

// 打卡更新请求
export interface PunchUpdateReqVO {
  commentText?: string // 修改字段名以匹配后端
  mood?: string
  achievements?: string[]
}

// 打卡详情响应
export interface PunchDetailRespVO extends PunchRespVO {
  relatedPlans?: Array<{
    planId: number
    planTitle: string
    completedTasks: number
    totalTasks: number
  }>
  readingGoals?: Array<{
    goalType: string
    targetValue: number
    actualValue: number
    isCompleted: boolean
  }>
}

// 打卡排行榜响应
export interface PunchRankingRespVO {
  userId: number
  userNickname: string
  userAvatar?: string
  streakDays: number
  totalPunchDays: number
  totalReadingTime: number
  rank: number
  isCurrentUser?: boolean
}

// 打卡成就响应
export interface PunchAchievementRespVO {
  id: number
  name: string
  description: string
  icon: string
  condition: string
  isUnlocked: boolean
  unlockDate?: string
  progress?: number
  maxProgress?: number
}

// 打卡提醒设置
export interface PunchReminderSettings {
  enableReminder: boolean
  reminderTime: string // HH:mm格式
  reminderDays: number[] // 0-6，0表示周日
  reminderMessage?: string
  enablePushNotification: boolean
  enableEmailNotification: boolean
}

// 打卡分享信息
export interface PunchShareInfo {
  punchId: number
  shareText: string
  shareImage: string
  shareUrl: string
  qrCodeUrl: string
}

// 打卡模板
export interface PunchTemplate {
  id: number
  name: string
  description: string
  moodOptions: string[]
  achievementOptions: string[]
  noteTemplates: string[]
  isDefault: boolean
}

// 打卡导出参数
export interface PunchExportParams {
  startDate: string
  endDate: string
  format: 'pdf' | 'excel' | 'csv'
  includeDetails?: boolean
  includeStats?: boolean
}
